import { Component, OnInit } from '@angular/core';
import { HttpService } from '@core/services/http.service';
import { ActivatedRoute, Router } from '@angular/router';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import swal from "sweetalert2";

@Component({
    selector: 'app-schcloud',
    templateUrl: './schcloud.component.html',
    styleUrls: ['./schcloud.component.less']
})
export class SchcloudComponent implements OnInit {

    loading = false;
    list: any = [];
    pageSize: number;
    pageIndex = 1;
    IP_PORT = this.Http.IP_PORT;
    total: number;
    token: string;
    sch_id = JSON.parse(localStorage.getItem('_user')).sch_id;
    style: any = {
        width: '70%'
    };
    constructor(private Http: HttpService,
        private msg: NzMessageService,
        private confirmServ: NzModalService,
        public router: Router,
        private ActiveRoute: ActivatedRoute) { }

    ngOnInit() {
        this.getData();
    }
    getData() {

        this.pageSize = 8;
        this.Http.getProject('cloud', { pi: this.pageIndex, ps: this.pageSize }).then(data => {
            this.list = [];
            this.list = this.list.concat(data.list);
            this.total = data.total;
            this.Http.getCloudBySchId({ sch_id: this.sch_id }).subscribe(res => {
                console.log(res)
                for (let ylist of this.list) {
                    ylist['isUse'] = false;
                    for (let klist of res['list']) {
                        if (ylist.p_id == klist.cloud_id) {
                            ylist.isUse = true
                        }
                    }
                }
            })
        });
    }


    preview(p_id, isCloud, isUse) {
        this.router.navigate(['/xiangmu/full/advance'], { relativeTo: this.ActiveRoute, queryParams: { p_id: p_id, isCloud: isCloud, isUse: isUse } });
    }

}
